package com.briup.utils;

import com.briup.bean.ShopCar;
import com.briup.service.IShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class SumPrice {

    @Autowired
    IShopCarService shopCarService;

    public BigDecimal getSumPrice(List<ShopCar> shopCarList){
        final BigDecimal[] sumPrice = {BigDecimal.ZERO};
        //计算总价格
        shopCarList.forEach(shop->{
            if(shop.getShop().isDiscount()) //假如是打折商品
            {
                sumPrice[0] = sumPrice[0].add(shop.getShop().getDiscountPrice().multiply(BigDecimal.valueOf(shop.getNum())));
            }
            else {
                sumPrice[0] = sumPrice[0].add(shop.getShop().getSelling_price().multiply(BigDecimal.valueOf(shop.getNum())));
            }
        });
        return sumPrice[0];
    }
}
